<template>
    <div>
        <!--          面包屑-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item >🏠</el-breadcrumb-item>
            <el-breadcrumb-item>用户基本信息</el-breadcrumb-item>
        </el-breadcrumb>
        <!--        卡片区域-->
        <el-card class="box-card">
            <el-row :gutter="20">
                <el-col :span="2"> <div class="chaxun">账号:</div></el-col>
                <el-col :span="4">
                    <el-input
                            placeholder="请输入用户名"
                            prefix-icon="el-icon-search"
                            v-model="yonghu">
                    </el-input>
                </el-col>
                <el-col :span="1" >
                    <el-button type="success" icon="el-icon-search" @click="chazhanghao" plain></el-button>
                </el-col>
                <el-col :span="3"  :push="1"> <div class="chaxun">获病风险:</div></el-col>
                <el-col :span="4" :push="1">
                    <el-select v-model="dengjivalue" placeholder="请选择">
                        <el-option
                                v-for="item in dengji"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-col>
                <el-col :span="3" :push="1"> <div class="chaxun">糖尿病类型:</div></el-col>
                <el-col :span="4" :push="1">
                    <el-select v-model="leixingvalue" placeholder="请选择">
                        <el-option
                                v-for="item in leixing"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="5"> <div class="chaxun">测评得分排序方式:</div></el-col>
                <el-col :span="4">
                    <el-select v-model="paixvvalue" placeholder="请选择">
                        <el-option
                                v-for="item in paixv"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-col>
                <el-col :span="4" :push="10">
                    <el-button type="danger"  @click="clear" plain>清空</el-button>
                </el-col>
            </el-row>
<!--            健康数据展示-->
            <el-table
                    :data="filhealthInformationlist"
                    stripe
                    style="width: 100%"
                    :row-class-name="tableRowClassName"
            >
                <el-table-column
                        type="index"
                        label="#"
                        width="50">
                </el-table-column>

                <el-table-column
                        prop="userName"
                        label="用户名"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="type"
                        label="糖尿病病型"
                        width="160">
                </el-table-column>
                <el-table-column
                        prop="timeOfDiagnosis"
                        label="病情起始时间"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="score"
                        label="测评得分"
                        width="130">
                </el-table-column>
                <el-table-column
                        prop="level"
                        label="风险等级"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="tips"
                        label="医生建议"
                        width="200"
                >
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit"
                                @click="handleUpdate(scope.row)"
                        >修改</el-button>
                        <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                @click="handleDelete(scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--     分页     -->
            <el-pagination
                    v-show="total>0"
                    :page-size="queryParams.pageSize"
                    :pager-count="11"
                    :current-page.sync="queryParams.pageNum"
                    :total="total"
                    @current-change="gethealthInformationlist"
            >
            </el-pagination>
            <!-- 修改健康信息对话框 -->
            <el-dialog :visible.sync="visible" width="500px" append-to-body>
                <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                    <el-form-item label="发布用户昵称" prop="userName">
                        <el-link>{{form.userName}}</el-link>
                    </el-form-item>
                    <el-form-item label="测评得分" prop="userName">
                        <el-link>{{form.score}}</el-link>
                    </el-form-item>
                    <el-form-item label="风险等级" prop="userName">
                        <el-link>{{form.level}}</el-link>
                    </el-form-item>
                    <el-form-item label="风险提示" prop="userName">
                        <el-link>{{form.tips}}</el-link>
                    </el-form-item>
                    <el-form-item label="糖尿病类型" prop="className">
                        <el-select v-model="form.type" placeholder="请选择">
                            <el-option
                                    v-for="item in leixing"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="病情起始时间" prop="time">
                        <el-date-picker clearable size="small" style="width: 200px"
                                        v-model="form.timeOfDiagnosis"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="选择发布时间">
                        </el-date-picker>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                </div>
            </el-dialog>
        </el-card>
    </div>

</template>

<script>
    export default {
        name: "jibenxinxi",
        data() {
            return {
                healthInformationlist: [],
                filhealthInformationlist: [],
                leixing: [{
                    value: '糖尿病一型',
                    label: '糖尿病一型'
                }, {
                    value: '糖尿病二型',
                    label: '糖尿病二型'
                }
               ],
                dengji: [{
                    value: 'A',
                    label: 'A'
                }, {
                    value: 'B',
                    label: 'B'
                },
                    {
                        value: 'C',
                        label: 'C'
                    },
                    {
                        value: 'D',
                        label: 'D'
                    },
                ],
                paixv: [{
                    value: 'ASC',
                    label: '按测评分数升序'
                }, {
                    value: 'DESC',
                    label: '按测评分数降序'
                }
                ],
                dengjivalue: '',
                leixingvalue:'',
                yonghu:'',
                paixvvalue:'',
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                // 弹出层标题
                title: "",
                // 是否显示修改弹出层
                visible: false,
                // 总条数
                total: 0,// 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                },

            }
        },
        created() {
            this.gethealthInformationlist()
        },
        methods: {
            reset() {
                this.form = {
                    id: null,
                    score: null,
                    timeOfDiagnosis: null,
                    type: null,
                    userName: null,
                    level: null,

                };
                // this.$refs['form'].resetFields();
                // this.resetForm("form");
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                this.$confirm('是否确认删除?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(async () => {
                    this.$http.delete(`healthInformation/`+ids).then(response => {
                        if (response.data.code == 200) {
                            this.$message({
                                showClose: true,
                                message: '删除成功',
                                type: 'success'
                            });
                            this.gethealthInformationlist();
                        } else {
                            this.$message({
                                showClose: true,
                                message: response.data.msg,
                                type: response.data.code
                            });
                        }
                    });
                }).catch(() => {

                });
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids
                const token = sessionStorage.getItem("token");
                this.$http.defaults.headers.common['Authorization'] = token;
                this.$http.get('healthInformation/'+ id).then(response => {
                    this.form = response.data.data.data;
                    this.title = "修改用户健康信息";
                    this.visible = true;
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            const token = sessionStorage.getItem("token");
                            this.$http.defaults.headers.common['Authorization'] = token;
                            this.$http.put('healthInformation',this.form).then(response => {
                                if (response.data.code === 200) {
                                    this.$message({showClose: true, message: "修改成功", type: "success"})
                                    this.visible = false;
                                    this.gethealthInformationlist();
                                }
                            });
                        }
                    }
                });
            },
            async gethealthInformationlist() {
                const token = sessionStorage.getItem("token");
                this.$http.defaults.headers.common['Authorization'] = token;
                const {data: res} = await this.$http.get("healthInformation/list?pageNum="+this.queryParams.pageNum+'&'+"pageSize="+this.queryParams.pageSize)
                this.healthInformationlist = res.data.data
                this.filhealthInformationlist = this.healthInformationlist
                console.log('用户',this.healthInformationlist)
                console.log('fil',this.filhealthInformationlist)
                this.total = res.data.total
            },
            chazhanghao() {
                console.log(this.yonghu)
                this.filhealthInformationlist = []
                this.filhealthInformationlist= this.healthInformationlist.filter((p) => {
                    return p.userName.indexOf(this.yonghu) !== -1
                })
            },
            clear(){
                    this.dengjivalue='',
                    this.leixingvalue='',
                    this.yonghu='',
                    this.paixvvalue=''
                    this.filhealthInformationlist=this.healthInformationlist
            }
        }
    }
</script>

<style scoped>
    .el-breadcrumb{
        margin-bottom: 12px;

    }
    .el-card{
        box-shadow: 0 1px 1px rgba(0,0,0,0.15);
    }
    .chaxun{

        height: 40px;
        text-indent: 1em;
        line-height: 2.5em;
        vertical-align: middle;
    }
</style>
